import { h } from "vue";
import XEUtils from "xe-utils";
import { VxeColumnPropTypes, VxeGlobalRendererHandles } from "../../../../../types/all";
import { createEditRender, createDefaultRender, createDefaultFilterRender, createFormItemRender, getComponent, getFilterOns, getCellEditFilterProps, handleConfirmFilter } from "./common";

export default {
    renderDefault: createDefaultRender(),
    renderCell: createDefaultRender(),
    renderEdit: createEditRender(),
    renderFilter(renderOpts: VxeColumnPropTypes.EditRender, params: VxeGlobalRendererHandles.RenderFilterParams) {
        const { column } = params;
        const { name, attrs }: any = renderOpts;
        return [
            h(
                "div",
                {
                    class: "vxe-table--filter-element-wrapper",
                },
                column.filters.map((option: any, oIndex: any) => {
                    const optionValue = option.data;
                    return h(getComponent(name), {
                        key: oIndex,
                        ...attrs,
                        ...getCellEditFilterProps(renderOpts, params, optionValue),
                        ...getFilterOns(renderOpts, params, option, () => {
                            // 处理 change 事件相关逻辑
                            handleConfirmFilter(params, XEUtils.isBoolean(option.data), option);
                        }),
                    });
                })
            ),
        ];
    },
    defaultFilterMethod: createDefaultFilterRender(),
    renderItemContent: createFormItemRender(),
};
